﻿/********************************************************************************
     File:																
            Manager.aspx.cs                         
     Description:
            商品订单管理
     Author:									
            DDBuildTools
            http://DDBuildTools.supesoft.com
     Finish DateTime:
            2012/8/23 20:00:26
     History:
*********************************************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using BingZi.HY.Core;
using BingZi.WebControls;
using NewLife.Reflection;
using NewLife.Web;

namespace BingZi.UIOrder
{
    public partial class Manager : System.Web.UI.Page
    {
        Int32 IDX = (Int32)Common.sink("IDX", MethodType.Get, 10, 0, DataType.Int);
        string CMD = (string)Common.sink("CMD", MethodType.Get, 10, 1, DataType.Str);
        protected void Page_Load(object sender, EventArgs e)
        {
            BingZiPermission.CheckPagePermission(CMD);
            if (!Page.IsPostBack)
            {
                OnStart();
            }
        }
        
        /// <summary>
        /// 开始操作
        /// </summary>
        private void OnStart()
        {
            app_Order ut = app_Order.FindByKeyForEdit(IDX);
            OnStartData(ut);
            switch (CMD)
            { 
                case "New":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "增加商品订单";
                    Hidden_Disp();
                    break;
                case "List":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "查看商品订单";
                    Hidden_Input();
                    ButtonOption.Visible = false;
                    AddEditButton();
                    break;
                case "Edit":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "修改商品订单";
                    Hidden_Disp();
                    AddDeleteButton();
                    break;
                case "Delete":
                    if (ut.Delete() > 0)
                    {
                        EventMessage.MessageBox(1, "删除成功", string.Format("删除ID:{0}成功!", IDX), Icon_Type.OK, Common.GetHomeBaseUrl("Default.aspx"));
                    }
                    else {
                        EventMessage.MessageBox(1, "删除失败", string.Format("删除ID:{0}失败!", IDX), Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
                    }
                    break;
                default :
                    EventMessage.MessageBox(2, "不存在操作字符串!", "不存在操作字符串!", Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
                    break;
            }
        }

        /// <summary>
        /// 增加修改按钮
        /// </summary>
        private void AddEditButton()
        {
            HeadMenuButtonItem bi = new HeadMenuButtonItem();
            bi.ButtonPopedom = PopedomType.Edit;
            bi.ButtonName = "商品订单";
            bi.ButtonUrl = string.Format("?CMD=Edit&IDX={0}", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi);
        }


        /// <summary>
        /// 增加删除按钮
        /// </summary>
        private void AddDeleteButton()
        {
            HeadMenuButtonItem bi = new HeadMenuButtonItem();
            bi.ButtonPopedom = PopedomType.Delete;
            bi.ButtonName = "商品订单";
            bi.ButtonUrlType = UrlType.JavaScript;
            bi.ButtonUrl = string.Format("DelData('?CMD=Delete&IDX={0}')", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi);

            HeadMenuButtonItem bi1 = new HeadMenuButtonItem();
            bi1.ButtonPopedom = PopedomType.List;
            bi1.ButtonIcon = "back.gif";
            bi1.ButtonName = "返回";
            bi1.ButtonUrl = string.Format("?CMD=List&IDX={0}", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi1);
        }

        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <param name="ut"></param>
        private void OnStartData(app_Order ut)
        {
                ProductID_Input.Text  = ut.ProductID.ToString();
                ProductID_Disp.Text = app_Product.FindByID(ut.ProductID) == null ? "" : app_Product.FindByID(ut.ProductID).Title;
                Phone_Input.Text = Phone_Disp.Text = ut.Phone.ToString();
                //Area_Input.Text = Area_Disp.Text = ut.Area.ToString();
                Address_Input.Text = Address_Disp.Text = ut.Address.ToString();
                ZipCode_Input.Text = ZipCode_Disp.Text = ut.ZipCode.ToString();
                Email_Input.Text = Email_Disp.Text = ut.Email.ToString();
                Express_Input.Text = Express_Disp.Text = ut.Express.ToString();
                ExpressNumber_Input.Text = ExpressNumber_Disp.Text = ut.ExpressNumber.ToString();
                BuyCount_Input.Text = BuyCount_Disp.Text = ut.BuyCount.ToString();
                BuyUserID_Input.Text = BuyUserID_Disp.Text =sys_UserTable.FindUserNameByID(ut.BuyUserID).ToString();
                BuyTime_Input.Text = BuyTime_Disp.Text = ut.BuyTime.ToString();
                BuyIP_Input.Text = BuyIP_Disp.Text = ut.BuyIP.ToString();
                //Status_Input.Text = Status_Disp.Text = EnumHelper.GetEnumTextVal(ut.Status, typeof(EnumProductStatus)); ;
                LastTime_Input.Text = LastTime_Disp.Text = ut.LastTime.ToString();
                LastUser_Input.Text = LastUser_Disp.Text = ut.LastUser.ToString();
                LastIP_Input.Text = LastIP_Disp.Text = ut.LastIP.ToString();
                Remark_Input.Text = Remark_Disp.Text = ut.Remark.ToString();
                WebHelper.BindList(Status_Input, typeof(EnumOrderStatus));
                WebHelper.SelectedListByValue(Status_Input, ut.Status);
                Status_Disp.Text = EnumHelper.GetEnumTextVal(ut.Status, typeof(EnumOrderStatus));
        }

        /// <summary>
        /// 隐藏输入框
        /// </summary>
        private void Hidden_Input()
        {
        ProductID_Input.Visible = false;
        Phone_Input.Visible = false;
        //Area_Input.Visible = false;
        Address_Input.Visible = false;
        ZipCode_Input.Visible = false;
        Email_Input.Visible = false;
        Express_Input.Visible = false;
        ExpressNumber_Input.Visible = false;
        BuyCount_Input.Visible = false;
        BuyUserID_Input.Visible = false;
        BuyTime_Input.Visible = false;
        BuyIP_Input.Visible = false;
        Status_Input.Visible = false;
        LastTime_Input.Visible = false;
        LastUser_Input.Visible = false;
        LastIP_Input.Visible = false;
        Remark_Input.Visible = false;
        
        }

        /// <summary>
        /// 隐藏显示框
        /// </summary>
        private void Hidden_Disp()
        {
            ProductID_Input.Visible = false;
            Phone_Input.Visible = false;
            //Area_Input.Visible = false;
            Address_Input.Visible = true;
            Address_Disp.Visible = false;
            ZipCode_Input.Visible = true;
            ZipCode_Disp.Visible = false;
            Email_Input.Visible = false;
            Express_Input.Visible = true;
            Express_Disp.Visible = false;
            ExpressNumber_Input.Visible = true;
            ExpressNumber_Disp.Visible = false;
            BuyCount_Input.Visible = false;
            BuyUserID_Input.Visible = false;
            BuyTime_Input.Visible = false;
            BuyIP_Input.Visible = false;
            Status_Input.Visible = true;
            Status_Disp.Visible = false;
            LastTime_Input.Visible = false;
            LastUser_Input.Visible = false;
            LastIP_Input.Visible = false;
            Remark_Input.Visible = true;
            Remark_Disp.Visible = false;
        
        }

        /// <summary>
        /// 增加/修改事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
        
            //int ProductID_Value = (int)Common.sink(ProductID_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            //string Phone_Value = (string)Common.sink(Phone_Input.UniqueID, MethodType.Post, 50, 1, DataType.Str);
            //int Area_Value = (int)Common.sink(Area_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            string Address_Value = (string)Common.sink(Address_Input.UniqueID, MethodType.Post, 512, 1, DataType.Str);
            string ZipCode_Value = (string)Common.sink(ZipCode_Input.UniqueID, MethodType.Post, 20, 1, DataType.Str);
            //string Email_Value = (string)Common.sink(Email_Input.UniqueID, MethodType.Post, 100, 1, DataType.Str);
            string Express_Value = (string)Common.sink(Express_Input.UniqueID, MethodType.Post, 50, 0, DataType.Str);
            string ExpressNumber_Value = (string)Common.sink(ExpressNumber_Input.UniqueID, MethodType.Post, 50, 0, DataType.Str);
            //int BuyCount_Value = (int)Common.sink(BuyCount_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            //int BuyUserID_Value = (int)Common.sink(BuyUserID_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            //DateTime BuyTime_Value = (DateTime)Common.sink(BuyTime_Input.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            //string BuyIP_Value = (string)Common.sink(BuyIP_Input.UniqueID, MethodType.Post, 50, 1, DataType.Str);
            int Status_Value = (int)Common.sink(Status_Input.UniqueID, MethodType.Post, 3, 1, DataType.Int);
            //DateTime LastTime_Value = (DateTime)Common.sink(LastTime_Input.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            //int LastUser_Value = (int)Common.sink(LastUser_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            //string LastIP_Value = (string)Common.sink(LastIP_Input.UniqueID, MethodType.Post, 50, 1, DataType.Str);
            string Remark_Value = (string)Common.sink(Remark_Input.UniqueID, MethodType.Post, 512, 0, DataType.Str);
            app_Order ut = app_Order.FindByKeyForEdit(IDX);
            
            //ut.ProductID = ProductID_Value;
            //ut.Phone = Phone_Value;
            //ut.Area = Area_Value;
            ut.Address = Address_Value;
            ut.ZipCode = ZipCode_Value;
            //ut.Email = Email_Value;
            ut.Express = Express_Value;
            ut.ExpressNumber = ExpressNumber_Value;
            //ut.BuyCount = BuyCount_Value;
            //ut.BuyUserID = BuyUserID_Value;
            //ut.BuyTime = BuyTime_Value;
            //ut.BuyIP = BuyIP_Value;
            ut.Status = Status_Value;
            ut.LastTime = DateTime.Now;
            ut.LastUser = Common.Get_UserID;
            ut.LastIP = WebHelper.UserHost;
            ut.Remark = Remark_Value;
            Int32 rInt = 0;
            if (CMD == "New")
            {
                rInt = ut.Insert();
            }
            else if (CMD == "Edit")
            {
                rInt = ut.Update();
            }
            else
            {
                EventMessage.MessageBox(2, "不存在操作字符串!", "不存在操作字符串!", Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
            }
            if (rInt > 0)
            {
                string OpTxt = string.Format("增加商品订单成功!(ID:{0})", rInt);
                if (CMD == "Edit")
                    OpTxt = string.Format("修改商品订单成功!(ID:{0})",IDX);
                EventMessage.MessageBox(1, "操作成功", OpTxt, Icon_Type.OK, Common.GetHomeBaseUrl("Default.aspx"));
            }
            else if (rInt == -2)
            {
                EventMessage.MessageBox(1, "操作失败", "操作失败,存在相同的键值(用户名/数据)!", Icon_Type.Alert, Common.GetHomeBaseUrl("Default.aspx"));
            }
            else
            {
                EventMessage.MessageBox(1, "操作失败", string.Format("操作失败,返回值:{0}!", rInt), Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
            }
        }
    }
}
